#ifndef SUBSTITUTIONLIST_H
#define SUBSTITUTIONLIST_H

#include <string>
#include <map>
#include <Windows.h>
#include "Log.h"

class SubstitutionList
{
public:
	static SubstitutionList& Instance();

	void UpdateSubstitutionItem(const std::string &srcUrl,const std::string &substitutionUrl);

	void RemoveSubstitutionItem(const std::string &srcUrl);

	std::string UrlHitTest(const std::string &srcUrl);

	const std::map<std::string,std::string>& UrlList() const
	{
		return m_list;
	}

	bool SaveSubstitutionList();

	const std::string empty;

private:
	static SubstitutionList *m_instance;

	SubstitutionList();

	SubstitutionList(const SubstitutionList &)
	{
		throw std::exception("SubstitutionList class do not allow copy operation.");
	}

	~SubstitutionList();

	SubstitutionList& operator=(const SubstitutionList &)
	{
		throw std::exception("SubstitutionList class do not allow assignment operation.");
	}

	void LoadUrls(char *urlData,size_t dataLength);

	void LoadUrl(char *urlData,size_t dataLength,std::string &url,std::string::size_type &index);

	void AppendUrl(std::string &buffer,const std::string &url);

	static log4cplus::Logger log;

	std::map<std::string,std::string> m_list;

	SRWLOCK m_lock;
};

#endif